﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jy123.DBUtility;
using System.Data;

namespace Jy123.BLL.User_Module
{
    public class User_TCenter
    {
        public User_TCenter()
        { }
        #region  成员方法
     
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Jy123.Model.User_Module.User_TCenter> GetModelList(string strWhere)
        {
            DataSet ds = GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        private DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,TName,Logo,FUser,FLevel,FColor,Capacity,CurrentClubs,Assets,Description,Vitality,UID,Cash,UsingTimes,TrainClub,TStatus ");
            strSql.Append(" FROM User_TCenter ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 返回好友的同类型组件
        /// </summary>
        /// <param name="FJType">组件类型</param>
        /// <param name="order">排序</param>
        /// <param name="userId">用户id</param>
        /// <returns>好友的同类型组件</returns>
        public List<Jy123.Model.User_Module.User_TCenter> GetFriendModelList(int FJType, string order, int userId)
        {
            StringBuilder strWhere = new StringBuilder();            
            strWhere.Append("FUser IN (");
            strWhere.Append("SELECT FFriend FROM User_Friend ");
            strWhere.AppendFormat("WHERE FUser = {0})", userId);
            if (!string.IsNullOrEmpty(order))
            {
                strWhere.Append(" ORDER BY " + order);
            }
            return GetModelList(strWhere.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Jy123.Model.User_Module.User_TCenter> DataTableToList(DataTable dt)
        {
            List<Jy123.Model.User_Module.User_TCenter> modelList = new List<Jy123.Model.User_Module.User_TCenter>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Jy123.Model.User_Module.User_TCenter model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Jy123.Model.User_Module.User_TCenter();
                    if (dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    model.TName = dt.Rows[n]["TName"].ToString();
                    model.Logo = dt.Rows[n]["Logo"].ToString();
                    if (dt.Rows[n]["FUser"].ToString() != "")
                    {
                        model.FUser = int.Parse(dt.Rows[n]["FUser"].ToString());
                    }
                    if (dt.Rows[n]["FLevel"].ToString() != "")
                    {
                        model.FLevel = int.Parse(dt.Rows[n]["FLevel"].ToString());
                    }
                    if (dt.Rows[n]["FColor"].ToString() != "")
                    {
                        model.FColor = int.Parse(dt.Rows[n]["FColor"].ToString());
                    }
                    if (dt.Rows[n]["Capacity"].ToString() != "")
                    {
                        model.Capacity = int.Parse(dt.Rows[n]["Capacity"].ToString());
                    }
                    if (dt.Rows[n]["CurrentClubs"].ToString() != "")
                    {
                        model.CurrentClubs = int.Parse(dt.Rows[n]["CurrentClubs"].ToString());
                    }
                    if (dt.Rows[n]["Assets"].ToString() != "")
                    {
                        model.Assets = decimal.Parse(dt.Rows[n]["Assets"].ToString());
                    }
                    model.Description = dt.Rows[n]["Description"].ToString();
                    if (dt.Rows[n]["Vitality"].ToString() != "")
                    {
                        model.Vitality = int.Parse(dt.Rows[n]["Vitality"].ToString());
                    }
                    if (dt.Rows[n]["UID"].ToString() != "")
                    {
                        model.UID = int.Parse(dt.Rows[n]["UID"].ToString());
                    }
                    if (dt.Rows[n]["Cash"].ToString() != "")
                    {
                        model.Cash = int.Parse(dt.Rows[n]["Cash"].ToString());
                    }
                    if (dt.Rows[n]["UsingTimes"].ToString() != "")
                    {
                        model.UsingTimes = int.Parse(dt.Rows[n]["UsingTimes"].ToString());
                    }
                    model.TrainClub = dt.Rows[n]["TrainClub"].ToString();
                    if (dt.Rows[n]["TStatus"].ToString() != "")
                    {
                        model.TStatus = int.Parse(dt.Rows[n]["TStatus"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        #endregion  成员方法
    }
}
